GList *windows;
};
+static gboolean
+gtk_application_focus_in_event_cb (GtkWindow *window,
+ GdkEventFocus *event,
+ GtkApplication *application)
+{
+ GtkApplicationPrivate *priv = application->priv;
+ GList *link;
+
+ /* Keep the window list sorted by most-recently-focused. */
+ link = g_list_find (priv->windows, window);
+ if (link != NULL && link != priv->windows)
+ {
+ priv->windows = g_list_remove_link (priv->windows, link);
+ priv->windows = g_list_concat (link, priv->windows);
+ }
+
+ return FALSE;
+}
+
static void
gtk_application_startup (GApplication *application)
{
priv->windows = g_list_prepend (priv->windows, window);
gtk_window_set_application (window, application);
g_application_hold (G_APPLICATION (application));
+
+ g_signal_connect (window, "focus-in-event",
+ G_CALLBACK (gtk_application_focus_in_event_cb),
+ application);
}
}
GtkWindow *window)
{
GtkApplicationPrivate *priv;
+ GList *link;
g_return_if_fail (GTK_IS_APPLICATION (application));
priv = application->priv;
- if (g_list_find (priv->windows, window))
+ link = g_list_find (priv->windows, window);
+ if (link)
{
- priv->windows = g_list_remove (priv->windows, window);
+ g_signal_handlers_disconnect_by_func (window,
+ gtk_application_focus_in_event_cb,
+ application);
+ priv->windows = g_list_remove_link (priv->windows, link);
g_application_release (G_APPLICATION (application));
gtk_window_set_application (window, NULL);
}
*
* Gets a list of the #GtkWindow<!-- -->s associated with @application.
*
- * The list that is returned should not be modified in any way.
+ * The list is sorted by most recently focused window, such that the first
+ * element is the currently focused window. (Useful for choosing a parent
+ * for a transient window.)
+ *
+ * The list that is returned should not be modified in any way. It will
+ * only remain valid until the next focus change or window creation or
+ * deletion.
*
* Returns: (element-type GtkWindow) (transfer none): a #GList of #GtkWindow
*